package edu.sysu.cshare.gui;

import java.awt.BorderLayout;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JTable;

import edu.sysu.cshare.control.HomeworkManager;
import edu.sysu.cshare.util.gui.TableModel_Homework_Un;
import javax.swing.ImageIcon;
import java.awt.Color;

public class Pnl_Homework extends JPanel {

	private JTabbedPane tabbedPane;
	private HomeworkManager homeworkManager;

	public static class Image {
		public static ImageIcon getViewDetail() {
			return new ImageIcon(
					Pnl_Homework.class
							.getResource("/edu/sysu/cshare/image/hm_detail.png"));
		}

		public static ImageIcon getReDownload() {
			return new ImageIcon(
					Pnl_Homework.class
							.getResource("/edu/sysu/cshare/image/hm_down.png"));
		}

		public static ImageIcon getSubmit() {
			return new ImageIcon(
					Pnl_Homework.class
							.getResource("/edu/sysu/cshare/image/hm_up.png"));
		}

		public static ImageIcon getCheckDone() {
			return new ImageIcon(
					Pnl_Homework.class
							.getResource("/edu/sysu/cshare/image/hm_check.png"));
		}

		public static ImageIcon getReUpload() {
			return new ImageIcon(
					Pnl_Homework.class
							.getResource("/edu/sysu/cshare/image/hm_reup.png"));
		}

		public static ImageIcon getInvalid() {
			return new ImageIcon(
					Pnl_Homework.class
							.getResource("/edu/sysu/cshare/image/homework_mgt_1.png"));
		}
	}

	public static class Naming {
		public static String getCourseName() {
			return "课程名称";
		}

		public static String getSubTooptip() {
			return "不需要上传的文件点击下面的对勾就会标记为已做完";
		}

		public static String getHomeworkDescrp() {
			return "作业描述";

		}

		public static String getDueDate() {
			return "截止日期";
		}

		public static String getViewDetail() {
			return "查看详情";
		}

		public static String getClickSubmit() {
			return "点击提交";
		}

		public static String getReSubmit() {
			return "重新提交";
		}

		public static String getSubDate() {
			return "提交日期";
		}

		public static String getReDownload() {
			return "重新下载";
		}
	}

	public void updateHomework() {
		if (tabbedPane != null) {
			remove(tabbedPane);
		}
		//System.out.println("in update homework");
		tabbedPane = new JTabbedPane(JTabbedPane.TOP);
		add(tabbedPane, BorderLayout.CENTER);

		Pnl_Homework_Un pnl_Homework_Un = new Pnl_Homework_Un(homeworkManager);
		pnl_Homework_Un.setForeground(new Color(224, 255, 255));
		pnl_Homework_Un.setBackground(new Color(224, 255, 255));
		tabbedPane
				.addTab("未完成",
						new ImageIcon(
								Pnl_Homework.class
										.getResource("/edu/sysu/cshare/image/homework_un_1.png")),
						pnl_Homework_Un, null);

		Pnl_Homework_Subed pnl_Homework_Subed = new Pnl_Homework_Subed(
				homeworkManager);
		pnl_Homework_Subed.setForeground(new Color(224, 255, 255));
		pnl_Homework_Subed.setBackground(new Color(224, 255, 255));
		tabbedPane.addTab("已完成", pnl_Homework_Subed);
		tabbedPane
				.setIconAt(
						1,
						new ImageIcon(
								Pnl_Homework.class
										.getResource("/edu/sysu/cshare/image/homework_done_1.png")));
		if (homeworkManager.getActor().canManageHomework()) {
			Pnl_Homework_Mgt pnl_Homework_Mgt = new Pnl_Homework_Mgt(
					homeworkManager);
			tabbedPane
					.addTab("管理",
							new ImageIcon(
									Pnl_Homework.class
											.getResource("/edu/sysu/cshare/image/homework_mgt_1.png")),
							pnl_Homework_Mgt, null);
		}
	}

	/**
	 * Create the panel.
	 */
	public Pnl_Homework(HomeworkManager homeworkManager) {
		setLayout(new BorderLayout(0, 0));
		this.homeworkManager = homeworkManager;
		updateHomework();
	}
}
